import { createClient } from '@supabase/supabase-js'

const supabaseUrl = import.meta.env.VITE_SUPABASE_URL
const supabaseAnonKey = import.meta.env.VITE_SUPABASE_ANON_KEY

if (!supabaseUrl || !supabaseAnonKey) {
  throw new Error('Missing Supabase environment variables')
}

export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey)

// 数据库表类型定义
export interface Database {
  public: {
    Tables: {
      movies: {
        Row: {
          id: number
          title: string
          original_title?: string
          cover_url: string
          video_url?: string
          rating: number
          year: number
          duration: string
          description: string
          plot?: string
          actors: string[]
          director: string
          uploader_id?: string
          views: number
          likes: number
          is_ai: boolean
          tags: string[]
          budget?: string
          box_office?: string
          awards?: string[]
          trivia?: string[]
          created_at: string
          updated_at: string
          cover_file_size?: number
        }
        Insert: {
          id?: number
          title: string
          original_title?: string
          cover_url: string
          video_url?: string
          rating: number
          year: number
          duration: string
          description: string
          plot?: string
          actors: string[]
          director: string
          uploader_id?: string
          views?: number
          likes?: number
          is_ai?: boolean
          tags?: string[]
          budget?: string
          box_office?: string
          awards?: string[]
          trivia?: string[]
          created_at?: string
          updated_at?: string
          cover_file_size?: number
        }
        Update: {
          id?: number
          title?: string
          original_title?: string
          cover_url?: string
          video_url?: string
          rating?: number
          year?: number
          duration?: string
          description?: string
          plot?: string
          actors?: string[]
          director?: string
          uploader_id?: string
          views?: number
          likes?: number
          is_ai?: boolean
          tags?: string[]
          budget?: string
          box_office?: string
          awards?: string[]
          trivia?: string[]
          created_at?: string
          updated_at?: string
          cover_file_size?: number
        }
      }
      user_profiles: {
        Row: {
          id: number
          user_id: string
          name: string
          avatar_url?: string
          bio?: string
          is_ai: boolean
          followers: number
          following: number
          uploads: number
          created_at: string
          updated_at: string
        }
        Insert: {
          id?: number
          user_id: string
          name: string
          avatar_url?: string
          bio?: string
          is_ai?: boolean
          followers?: number
          following?: number
          uploads?: number
          created_at?: string
          updated_at?: string
        }
        Update: {
          id?: number
          user_id?: string
          name?: string
          avatar_url?: string
          bio?: string
          is_ai?: boolean
          followers?: number
          following?: number
          uploads?: number
          created_at?: string
          updated_at?: string
        }
      }
      comments: {
        Row: {
          id: number
          movie_id: number
          user_id: string
          content: string
          likes: number
          dislikes: number
          parent_id?: number
          created_at: string
          updated_at: string
        }
        Insert: {
          id?: number
          movie_id: number
          user_id: string
          content: string
          likes?: number
          dislikes?: number
          parent_id?: number
          created_at?: string
          updated_at?: string
        }
        Update: {
          id?: number
          movie_id?: number
          user_id?: string
          content?: string
          likes?: number
          dislikes?: number
          parent_id?: number
          created_at?: string
          updated_at?: string
        }
      }
    }
  }
} 